<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>资管客户还款管理</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
    <form id="insCstRepay_form">
        <div class="fieldset1 tabel_col tabel_col_1 clearFix">
            <div class="fieldBox col_100">
                <div class="label">资方支付表号</div>
                <div class="field">
                    ${insCstRepaySettleVO.paySchNo}
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">还款资金来源</div>
                <div class="field">
                    <input name="accTypCd" id="accTypCd" data-value="" placeholder="请选择" ltype="combobox" validate="{required:true,select:true}">
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_100" id="errorMsgDiv" style="display:none;">
                <div class="label">错误描述</div>
                <div class="field">
                    <span class="requiredSymbol" id="errorMsg">${errorMsg}</span>
                </div>
            </div>
        </div>
    </form>

    <div id="ligergrid" class="sq-grid"></div>
<script>
    var grid = null,form=null;
    $(function() {
         form = $("#insCstRepay_form").ligerForm({
            validate: true
        });

        $("#accTypCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        liger.get("accTypCd").setData(${accTypCdList});

        if("${errorFlag}"=="1"){
            $("#errorMsgDiv").show();
        }

        grid = $("#ligergrid").ligerGrid({
            columns: [
                { display: '期次', name: 'payPd', minWidth: 50 ,align:'left'},
                { display: '本金', name: 'repayCapAmt', minWidth: 80,align:'left',},
                { display: '利息', name: 'repayIntrAmt', minWidth: 80,align:'left'},
                { display: '罚息', name: 'repayPnlAmt', minWidth: 80,align:'left'},
            ],
            usePager: false,
            root: 'rows',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: false,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false
        });
        grid.setHeight(100);
        grid.loadData(${repayList});

        var dialog = frameElement.dialog; //调用页面的dialog对象(ligerui对象)
        //按钮在页面外的Dialog里，给Dialog绑定事件 （onOk 和 onCancel）
        frameElement.dialog.onOk = function () {
            if("${errorFlag}"=="1"){
                $.ligerDialog.SQalert({content: "查询三方欠款明细失败，不能操作贷款还款", SQ_type: "error", SQ_showButtons: true});
                return false;;
            }
            if (!form.valid()) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            frameElement.dialog.disabledBtns();
            frameElement.dialog.mask();

            var accTypCd=liger.get("accTypCd").selectedValue;
            var _url= '<%=path%>/repay/insCstRepaySettle/repayOrsettle.do';
            var data = {"id":"${insCstRepaySettleVO.id}","prjId":"${insCstRepaySettleVO.prjId}","insId":"${insCstRepaySettleVO.insId}","type":"repay","accTypCd":accTypCd};
            var wait_dialog;

            $.ligerDialog.confirm("是否确定提前还款？", function (flag) {
                if (flag == false) return;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: data,
                    url: _url,
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                            frameElement.dialog.close();
                        } else {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error", SQ_showButtons: true});
                        }
                    }
                });
            });
        }

        frameElement.dialog.onCancel = function () {
            frameElement.dialog.hide();
        };

    });
</script>
</body>
</html>
